module.exports = function($scope, $resource, $state, $stateParams, shakedevice, shakedeviceinfo, dictbytypelist,
  shakecompanyinfolist, shakegroupinfolist, getDate, savedevicerecode, userinfo, toaster, date2str, str2date){
  $scope.obj = {};
  $scope.info = {};
  $scope.isshow = '1'; // 创建
  
  $scope.vm = {
    'date' : '',
    'options' : {
        format: "YYYY-MM-DD",
        locale : 'zh-cn'
    }
  }
  $scope.search = {
    'isSelected' : {
      
    }
  }

  //用户信息
	function isable()
	{
		userinfo().then(function(res) {
			$scope.company_code = res.company_code;
	    if(res.company_code != 'L0002')
          {
            $scope.isable = '1';
          }
      console.log(res);
    });
      console.log('xiangqing');
	}
  //机器设备id
  var id = $stateParams.id;
  console.log(id);
  // 详情
  if (id) {
    $resource('/api/as/gc/shakedevice/getone', {}, {}).
    save({'id' : id},function (res) {
        if (res.errcode != 0) {
            toaster.error({title:"",body:res.errmsg});
            return;
        }
        console.log('详情');
        $scope.obj = res.data;
        // if($scope.obj.binding_type == '1') {
        //   $scope.info.binding_name = '旅行社';
        // } else if($scope.obj.binding_type == '2'){
        //   $scope.info.binding_name = '景区';
        // }
        $resource('/api/as/tc/place/findPlaceCodeNameList', {}, {}).
        save({'binding_company_code' : res.data.binding_company_code},function (res) {
            if (res.errcode != 0) {
                toaster.error({title:"",body:res.errmsg});
                return;
            }
            console.log('绑定类型');
            $scope.companyarr = res.data;
            console.log($scope.companyarr);
  
        });
    })
  }
    // 设备绑定类型
  function deviceBindType() {
    dictbytypelist({}).then(function(res) {
      console.log(res);
      console.log('~~~~~~~~~');
      if(res.errcode === 0){
          $scope.typearr = res.data;
          console.log($scope.typearr);
      }
    });
  }
  deviceBindType();
  $scope.changeDeviceType = function(type){
    console.log(type);
    if(type == '1'){
      $scope.info.binding_type = 'M';
    } else if(type = '2'){
      $scope.info.binding_type = 'J';
    }
    getCompany($scope.info.binding_type);
  }
  
  function getCompany(type){
      console.log('jmh');
      $scope.companyarr = [];
      $resource('/api/as/tc/place/findPlaceCodeNameList', {}, {}).
      save({'type' : type},function (res) {
          if (res.errcode != 0) {
              toaster.error({title:"",body:res.errmsg});
              return;
          }
          console.log('绑定类型');
          $scope.companyarr = res.data;
          console.log($scope.companyarr);

      });
      
  }

  $scope.gogo = function(){
    console.log($scope.obj);
    $resource('/api/as/gc/shakedevice/save', {}, {}).
    save($scope.obj, function(res){
      console.log(res);
      if(res.errcode !== 0)
      {
          alert(res.errmsg);
          return;
      }
      alert('操作成功');
      $state.go('app.shakedevicelist');
    })
  }

};


